home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / IOCTL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  1.0 KB  |  40 lines

  1. /* IOCTL.C --- p. 638 */
  2. #include <stdio.h>
  3. #include <io.h>
  4. #define RAW_BIT 0x20
  5. main(int argc, char **argv)
  6. {
  7.     int raw_mode, handle = 1,            /* standard output */
  8.         cmd, argdx;
  9.     if(argc <2)
  10.     {
  11.         printf("Usage: %s <COOKED or RAW>\n", argv[0]);
  12.         exit(0);
  13.     }
  14.     if((strcmp(argv[1], "COOKED") == 0) ||
  15.             (strcmp(argv[1], "cooked") == 0)) raw_mode = 0;
  16.     else
  17.     {
  18.         if((strcmp(argv[1], "RAW") == 0) ||
  19.                 (strcmp(argv[1], "raw") == 0)) raw_mode = 1;
  20.         else
  21.         {
  22.             printf("Unknown mode: %s\n", argv[1]);
  23.             exit(0);
  24.         }
  25.     }
  26.             /* Get device information (cmd = 0) using IOCTL */
  27.     cmd = 0;
  28.     ioctl(handle, cmd, &argdx);
  29.             /* Set raw/cooked bit on or off depending on value
  30.              * of variable "raw_mode" */
  31.     argdx &= 0xff;
  32.     if(raw_mode) argdx |= RAW_BIT;
  33.     else argdx &= (-RAW_BIT);
  34.             /* Call ioctl to set the raw/cooked mode bit */
  35.     cmd = 1;
  36.     ioctl(handle, cmd, &argdx);
  37.     printf("Standard output is now in %s mode\n", argv[1]);
  38.     printf("(If mode is RAW, remember to reset it to "
  39.                     "COOKED when you are done)");
  40. }